//
//  HLSubTagTableViewCell.m
//  HL-百思不得姐
//
//  Created by admin on 16/5/12.
//  Copyright © 2016年 CHL. All rights reserved.
//

#import "HLSubTagTableViewCell.h"
#import "HLSubTagItem.h"
#import <UIImageView+WebCache.h>

@interface HLSubTagTableViewCell()

@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

@property (weak, nonatomic) IBOutlet UILabel *numLabel;

@end

@implementation HLSubTagTableViewCell

//重写setFrame方法
-(void)setFrame:(CGRect)frame{
    
    frame.size.height -= 1;
    
    [super setFrame:frame];
}

-(void)setItem:(HLSubTagItem *)item
{
    _item = item;
    
    self.nameLabel.text = item.theme_name;
    
    [self resovelNum];
    
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:item.image_list] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"] options:SDWebImageCacheMemoryOnly completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        // 1.开启图形上下文
        // NO:不要透明,NO是要透明;比例因素0:当前点与像素比例,0是根据屏幕自适应匹配
        UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
        // 2.描述裁剪区域
        UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
        // 3.设置裁剪区域;
        [path addClip];
        // 4.画图片
        [image drawAtPoint:CGPointZero];
        // 5.取出图片
        image = UIGraphicsGetImageFromCurrentImageContext();
        // 6.关闭上下文
        UIGraphicsEndImageContext();
        
        self.iconImageView.image = image;
    }];
}

//处理订阅数字
- (void)resovelNum{
    NSString *numStr = [NSString stringWithFormat:@"%@人订阅",self.item.sub_number];
    NSInteger num = numStr.integerValue;
    if (num > 10000) {
        CGFloat numF = num / 10000.0;
        numStr = [NSString stringWithFormat:@"%.1f万人订阅",numF];
        //将小数点后为0的字符串省略掉
        numStr = [numStr stringByReplacingOccurrencesOfString:@".0" withString:@""];
    }
    
    self.numLabel.text = numStr;
}

//从xib加载就会调用一次
- (void)awakeFromNib {
  
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

   
}

@end
